package com.linghang.demo.controller;

import com.linghang.demo.req.FootPicQueryReq;
import com.linghang.demo.req.FootPicSaveReq;
import com.linghang.demo.resp.CommonResp;
import com.linghang.demo.resp.FootPicQueryResp;
import com.linghang.demo.resp.PageResp;
import com.linghang.demo.service.FootPicService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

//工作室简介
@RestController
@RequestMapping ("/foot")
public class FootPicController {


    @Resource
    private FootPicService foot_picService;

    @Resource
    private  FileController fileController;


    @Value("${Act.path}")
    private String path;  //域名地址

//    @GetMapping("/list1")
//    public CommonResp list() {
//        CommonResp<List<FootPic>> resp = new CommonResp<>();
//        List<FootPic> list = foot_picService.list();
//        resp.setContent(list);
//        return resp;
//    }
    @GetMapping("/list")
    public CommonResp list(@Valid FootPicQueryReq req) {
        CommonResp<PageResp<FootPicQueryResp>> resp = new CommonResp<>();
        PageResp<FootPicQueryResp> list = foot_picService.list(req);
        resp.setContent(list);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable int id){
        CommonResp resp=new CommonResp<>();
        foot_picService.delete(id);

        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody FootPicSaveReq req
                           ) throws IOException {

//        String fileName = path + UploadUtils.uploadImg(file);
//        req.setUrl(fileName);
        CommonResp resp = new CommonResp<>();
        req.setUrl(fileController.getImgPath());
        foot_picService.save(req);
        return resp;
    }
}